package com.lvan.producer.send;

import com.lvan.producer.channel.MySource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * @author luom
 * @date 2021/9/3
 * <p>
 * EnableBinding(Source.class) // 用于‘交换机’与‘通道’相互绑定
 */
@Component
@EnableBinding(MySource.class)
public class MessageProducer {

    @Autowired
    private MySource mySource;

    /**
     * 发送消息
     *
     * @param message 消息体
     */
    public void send(String message) {
        mySource.myOutput().send(MessageBuilder.withPayload(message).build());
    }
}
